<template>
  <el-dialog
      v-model="pileDialogVisible"
      title="充电桩信息"
      width="50%"
  >
    <el-form :model="pileForm" label-width="100px">
      <el-form-item label="充电桩名称">
        <el-input v-model="pileForm.pileName" />
      </el-form-item>
      <el-form-item label="充电桩编号">
        <el-input v-model="pileForm.pileCode" />
      </el-form-item>
      <el-form-item label="类型">
        <el-input v-model="pileForm.pileType" />
      </el-form-item>
      <el-form-item label="功率 (kW)">
        <el-input-number v-model="pileForm.pilePower" :min="0" />
      </el-form-item>
      <el-form-item label="型号">
        <el-input v-model="pileForm.pileModel" />
      </el-form-item>
      <el-form-item label="描述">
        <el-input v-model="pileForm.pileDesc" />
      </el-form-item>
      <el-form-item label="适用车型">
        <el-input v-model="pileForm.suitableVehicle" />
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="pileForm.pileStatus">
          <el-option label="空闲中" :value="'空闲中'" />
          <el-option label="使用中" :value="'使用中'" />
        </el-select>
      </el-form-item>
      <el-form-item label="图片 URL">
        <el-input v-model="pileForm.pileImgUrl" />
      </el-form-item>
    </el-form>

    <template #footer>
      <el-button @click="pileDialogVisible = false">取消</el-button>
      <el-button type="primary" @click="onSavePile">保存</el-button>
    </template>
  </el-dialog>
</template>

<script>
import { toRefs } from 'vue';
import { usePileForm } from '@/composables/stationUsePileForm.js';

export default {
  name: 'PileForm',
  props: {
    chargingPiles: {
      type: Array,
      default: () => [],
    },
  },
  setup(props) {
    // 从 stationUsePileForm 获取弹窗与表单数据
    const {
      pileDialogVisible,
      pileForm,
      isAddingPile,
      openPileDialog,
      savePile,
      removePile,
    } = usePileForm();

    // 保存充电桩
    const onSavePile = () => {
      savePile(props.chargingPiles);
    };

    return {
      pileDialogVisible,
      pileForm,
      isAddingPile,
      openPileDialog,
      savePile,
      removePile,
      onSavePile,
    };
  },
};
</script>
